import * as vscode from 'vscode';
import {dedent} from "../../../utils";

// documentation中使用了代码块，代码块中写的事makedown格式，首行不能为空
let rotateViewItems = [
    {
        "label": "RotateView_Create",
        "insertText": dedent`
        local param = {
            [1] = {scale = \${1:0.4}, img = \${2:"res/public/word_fubentg_1.png"}},
            [2] = {scale = \${3:0.6}, img = \${4:"res/public/word_fubentg_2.png"}},
            [3] = {scale = \${5:0.8}, img = \${6:"res/public/word_fubentg_3.png"}},
            [4] = {scale = \${7:1.0}, img = \${8:"res/public/word_fubentg_4.png"}},
            [5] = {scale = \${9:0.8}, img = \${10:"res/public/word_fubentg_5.png"}},
            [6] = {scale = \${11:0.6}, img = \${12:"res/public/word_fubentg_6.png"}},
            [7] = {scale = \${13:0.4}, img = \${14:"res/public/word_fubentg_7.png"}}
        }
        local view = GUI:RotateView_Create(\${15:parent}, \${16:"rotateView_1"}, \${17:500}, \${18:320}, \${19:1000}, \${20:500}, \${21:100}, param)
        `,
        "documentation": dedent`# 创建旋转容器
        ## RotateView_Create(parent, ID, x, y, width, scrollGap, param)

        | 参数      | 必选 | 类型   | 注释                 |
        | :-------- | :--- | :----- | :------------------- |
        | parent    | 是   | obj    | 父节点对象           |
        | ID        | 是   | string | 唯一ID               |
        | x         | 是   | int    | 位置 横坐标          |
        | y         | 是   | int    | 位置 纵坐标          |
        | width     | 是   | int    | 宽度                 |
        | height    | 是   | int    | 高度                 |
        | scrollGap | 是   | int    | 滑动间隙, 默认100    |
        | param     | 是   | table  | 子节点参数, 参考如下 |

        \`\`\`
        列表各子节点参数 scale: 缩放大小 img: 图片路径 string node:自定义控件 (img和node不同时存在)
        {
            [1] = {scale = 0.4},
            [2] = {scale = 0.6},
            [3] = {scale = 0.8},
        }
        \`\`\`
        `
    },
    {
        "label": "RotateView_addChild",
        "insertText": dedent`
        GUI:RotateView_addChild(\${1:widget}, \${2:value}, \${3:index})
        `,
        "documentation": dedent`# 添加子节点到旋转容器对应下标item
        ## RotateView_addChild(widget, value, index)

        | 参数   | 必选 | 类型 | 注释         |
        | :----- | :--- | :--- | :----------- |
        | widget | 是   | obj  | 旋转容器对象 |
        | value  | 是   | obj  | 控件对象     |
        | index  | 是   | int  | 对应下标     |
        `
    },
    {
        "label": "RotateView_getChildByIndex",
        "insertText": dedent`
        local child = GUI:RotateView_getChildByIndex(\${1:widget}, \${2:index})
        `,
        "documentation": dedent`# 获取对应下标item添加的子节点
        ## RotateView_getChildByIndex(widget, index)

        | 参数   | 必选 | 类型 | 注释         |
        | :----- | :--- | :--- | :----------- |
        | widget | 是   | obj  | 旋转容器对象 |
        | index  | 是   | int  | 对应下标     |

        - 仅能获取RotateView_addChild方法添加的控件.
        `
    },
    {
        "label": "RotateView_getItemByIndex",
        "insertText": dedent`
        local item = GUI:RotateView_getItemByIndex(\${1:widget}, \${2:index})
        `,
        "documentation": dedent`# 获取对应下标item
        ## RotateView_getItemByIndex(widget, index)

        | 参数   | 必选 | 类型 | 注释         |
        | :----- | :--- | :--- | :----------- |
        | widget | 是   | obj  | 旋转容器对象 |
        | index  | 是   | int  | 对应下标     |

        - 示例代码
        \`\`\`
        local param = {
            [1] = {scale = 0.4, img = "res/public/word_fubentg_1.png"},
            [2] = {scale = 0.6, img = "res/public/word_fubentg_2.png"},
            [3] = {scale = 0.8, img = "res/public/word_fubentg_3.png"},
            [4] = {scale = 1.0, img = "res/public/word_fubentg_4.png"},
            [5] = {scale = 0.8, img = "res/public/word_fubentg_5.png"},
            [6] = {scale = 0.6, img = "res/public/word_fubentg_6.png"},
            [7] = {scale = 0.4, img = "res/public/word_fubentg_7.png"},
        }
        local view = GUI:RotateView_Create(GUI:Attach_LeftBottom(), "rotateView_1", 500, 320, 1000, 500, 100, param)
        local item = GUI:RotateView_getItemByIndex(view, 3)
        local itemSize = GUI:getContentSize(item)
        local layout = GUI:Layout_Create(item, "clickLayout", 0, 0, itemSize.width, itemSize.height)
        GUI:setTouchEnabled(layout, true)
        GUI:setSwallowTouches(layout, false)
        GUI:addOnClickEvent(layout, function()
            SL:Print("Click item index 3 !")
            GUI:removeFromParent(view)
        end)
        \`\`\`
        `
    }
]


export function getCompletionItems(): vscode.CompletionItem[] {


    const completionItems: vscode.CompletionItem[] = [];
    rotateViewItems.forEach((item: any) => {
        completionItems.push(createFunctionCompletionItem(item.label, item.insertText, item.documentation));
    });
    return completionItems;
}

function createFunctionCompletionItem(label: string, insertText: string, documentation?: string): vscode.CompletionItem {
    const item = new vscode.CompletionItem(label, vscode.CompletionItemKind.Function);
    item.insertText = new vscode.SnippetString(insertText);
    if (documentation) {
        item.documentation = new vscode.MarkdownString(documentation);
    }
    return item;
}
